﻿@{
	ViewBag.Title = "Format Source Code";
}

@*<script type="text/javascript">
	$(document).ready(function () {
		$(".teavchSourceCodeFormatter").each(function () {

			var container = this;
			var language = container.getAttribute("scl");
			//var code = container.innerText;
			var code = container.innerHtml;
			if (language != '' && language != 'undefined'
				&& code != null && code != 'undefined' && code != '') {
				$.post("http://localhost:55832/Tool/FormatCode", { id: language, code: code },
						function (obj) {
							container.innerHTML = obj; //set the rating attribute
						}
				);
			}
			else {
				container.innerHTML = "No source code found in container"; //set the rating attribute
			}

		});

	})
</script>*@
<div>
	This is original content<br />
	<div>select * from dbo.MyTable where Name like 'tea%'</div>
	<br />
	<br />
	This is formatted content<br />
	<br />
	<code class="teavchSourceCodeFormatter" scl="CSharpFormatter">	private bool SetSocket()
	{
		bool status = false;
		try
		{
			//HostName hostName = null;
			try
			{
				this.Server.HostName = new HostName( this.Server.Name );
				//hostName = new HostName( this.Server.Name );
				try
				{
					if ( this.Link == null || ( this.Link.Information.RemoteServiceName == "" ) )
					{
						this.Link = null;
						this.Link = new StreamSocket();
						//set write for your socket
						this.Writer = new DataWriter( this.Link.OutputStream );
						//set reader for your socket
						this.Reader = new DataReader( this.Link.InputStream );
						//define if partial reads are allowed
						this.Reader.InputStreamOptions = Windows.Storage.Streams.InputStreamOptions.Partial;
						//set Outbound buffer size
						this.Link.Control.OutboundBufferSizeInBytes = Channel.MaxBufferSize;
						//open connection
						this.Link.ConnectAsync( this.Server.HostName, this.Server.Port, SocketProtectionLevel.Ssl );
						Misc.Delay( 5000 );
						do
						{ }
						while ( this.Link.Information.RemoteHostName == null );

						this.Reader.LoadAsync( Channel.MaxBufferSize );
						string s = "";
						do
						{
							s = this.Reader.ReadLine();
							if ( s.StartsWith( IMAPResponses.StarOK ) )
							{
								status = true;
							}
						}
						while ( this.Reader.UnconsumedBufferLength != 0 );
					}
				}
				catch ( Exception ex )
				{
					this.Link = null;
					status = false;
				}
			}
			catch ( ArgumentException ex )
			{
				this.Link = null;
				status = false;
			}
		}
		catch ( Exception ex )
		{
			this.Link = null;
			status = false;
		}
		return status;
	}
	</code>
	<br />
</div>
